package v1

import (
	"gitee.com/youkelike/ziam/zvalidation"
	"gitee.com/youkelike/ziam/zvalidation/field"
)

func (u *User) Validate() field.ErrorList {
	// val := zvalidation.NewValidator(u)
	// allErrs := val.Validate()

	allErrs := zvalidation.ValidateStruct(u)

	if err := zvalidation.IsValidPassword(u.Password); err != nil {
		allErrs = append(allErrs, field.Invalid(field.NewPath("password"), err.Error(), ""))
	}

	return allErrs
}

func (u *User) ValidateUpdate() field.ErrorList {
	val := zvalidation.NewValidator(u)
	allErrs := val.Validate()

	return allErrs
}

func (s *Secret) Validate() field.ErrorList {
	val := zvalidation.NewValidator(s)

	return val.Validate()
}

func (p *Policy) Validate() field.ErrorList {
	val := zvalidation.NewValidator(p)

	return val.Validate()
}
